//
//  KeyChain.m
//  iOSBaseFramework
//
//  Created by user on 2020/6/17.
//  Copyright © 2020 com.taylor. All rights reserved.
//

#import "TRKeyChain.h"
#import "NSString+tool.h"
@implementation TRKeyChain


+ (instancetype)shareManage {
    static TRKeyChain *shareManage = nil;
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        shareManage = [[TRKeyChain alloc] init];
    });
    return shareManage;
}


- (id) init {
    self = [super init];
    if (self) {
        _viewControllerDic = [[NSMutableDictionary alloc] initWithCapacity:1];
    }
    return self;
}

+ (BOOL) validUsedIntValue:(NSString *)value
{
    if (value == nil || (NSNull *)value == [NSNull null]) {
        return NO;
    }
    return YES;
}


+ (NSString *)stringWithGBK2312:(NSString *)source
{
    NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
    char * c_test = "北京";
    unsigned long len = strlen(c_test);
    NSString *retStr = [[NSString alloc] initWithBytes:c_test length:len encoding:enc];
    return retStr;
}

+ (BOOL)isContainMandarin:(NSString *)str
{
    for (int i = 0; i < [str length]; i++) {
        int a = [str characterAtIndex:i];
        if (a > 0x4e00 && a < 0x9fff) {
            return YES;
        }
    }
    return NO;
}


- (void)saveUserToken:(NSString *)token {
    if ([token isEmptyString]) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"token"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return ;
    }
    
    [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"token"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)getUserToken
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
}


- (void) showMessage:(NSString *)message withSuperView:(UIView *)superView {
    
}

@end
